
exports.searchMarket = function (req, res) {

    //获取restful参数
    var restfulParams = req.routeInfo.restfulParams;

    //最终结果
    var resultData = {};
    //任务流创建
    async.waterfall([
            //1.营销招生
            function (cb) {
                R.SEND_HTTP(
                    req,
                    {
                        url: CORE_APIConfig.coreAPI.searchMarket + "/mm_time/" + restfulParams.time,
                        method: 'GET'
                    },
                    function (err, data) {
                        //判断是否有错误信息
                        if (err) {
                            return cb(err, data);
                        }
                        if(data.data.length>0){
                            resultData.Market = data.data[0];
                        }else{
                            resultData.Market = [];
                        }
                        cb();
                    }
                );

            },

            // 2. 营销招生获取营销内参

            function (cb) {
                if(resultData.Market != []){
                R.SEND_HTTP(
                    req,
                    {
                        url: CORE_APIConfig.coreAPI.searchReference + "/r_id/" + resultData.Market.mm_reference_id,
                        method: 'POST',
                        data: {
                            fields: [ "r_id","r_title","r_content","create_time"].join(",")
                        }
                    },
                    function (err, data) {
                        //判断是否有错误信息
                        if (err) {
                            console.log(data);
                            return cb(err, data);
                        }

                        resultData.Market.mm_reference_id= data.data[0];

                        cb();
                    }
                );
                }else{
                    cb();
                }

            },
        ], function (err, result) {

            //返回最终拼接结果
            RES.response(res, true, resultData);

        }
    );

}